package com.traffic.managent.model.system;

import java.util.List;

import com.traffic.managent.annotation.ModelBind;
import com.traffic.managent.base.CxBaseModel;

@ModelBind(table = "cx_department", key = "ids")
public class Department extends CxBaseModel<Department> {

	private static final long serialVersionUID = 1L;
	public static final Department dao = new Department();

	public String queryChildIds(String departmentId) {
		String sql = "";
		if ("100".equals(departmentId)) {// 管理员时
			sql = "SELECT ids FROM `cx_department` WHERE (paths LIKE '%" + departmentId + "/%' OR ids = '"
					+ departmentId + "') and delFlag = '0' ";
		} else {
			sql = "SELECT ids FROM `cx_department` WHERE (paths LIKE '%/" + departmentId + "/%' OR ids = '"
					+ departmentId + "') and delFlag = '0' ";
		}
		List<Department> deps = dao.find(sql);
		StringBuffer LongIds = new StringBuffer();
		for (Department department : deps) {
			LongIds.append(department.getStr("ids")).append(",");
		}
		LongIds.deleteCharAt(LongIds.length() - 1);

		return LongIds.toString();
	}
}